在製作鬧鐘時,由於會需要用到Realm這個第三方套件,所以今天就來了解一下。
一開始是因為要學習Realm的用法,發現Realm要先用Cocoapods安裝,糟糕的是安裝Cocoapods時的時候跳出了下面這個東西
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
在網路上搜尋一下之後,發現問題可能是出在ruby的版本太舊,於是輸入
% ruby -v
解果顯示版本確實太舊,需要更新一下
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
為了更新ruby,輸入
% brew install ruby
然後就是一陣等待和一堆下載之後,跳出下面這些東西
You may want to add this to your PATH.
ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH, run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
大致看來應該是類似說明,於是按照說明設置PATH
% echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.zshrc
% export LDFLAGS="-L/usr/local/opt/ruby/lib" >> ~/.zshrc
% export CPPFLAGS="-I/usr/local/opt/ruby/include" >> ~/.zshrc
然後輸入
% source ~/.zshrc
就能看到已安裝的ruby,再來就是確保ruby
% ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin20]
% which ruby
/usr/local/opt/ruby/bin/ruby
再次嘗試安裝Cocoapods了,輸入
% sudo gem install -n /usr/local/bin cocoapods
最後跳出下面這些就表示安裝成功了,可以開始使用啦
Done installing documentation for nanaimo, colored2, claide, CFPropertyList, atomos, xcodeproj, ruby-macho, nap, molinillo, gh_inspector, fourflusher, escape, cocoapods-try, netrc, cocoapods-trunk, cocoapods-search, cocoapods-plugins, cocoapods-downloader, cocoapods-deintegrate, ffi, ethon, typhoeus, public_suffix, fuzzy_match, concurrent-ruby, httpclient, algoliasearch, addressable, zeitwerk, tzinfo, i18n, activesupport, cocoapods-core, cocoapods after 47 seconds
也可以直接輸入下面這串安裝Cocoapods
% brew install cocoapods
到這裡就能開始使用Cocoapods裡的東西了,明天就能初次嘗試使用Realm了。